package polarizedMF;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Step6_Ordinal_FinalResults {

	/**
	 * @param args
	 */
	
	public Step6_Ordinal_FinalResults(String svm_dataset, String fold, String epsilon) throws IOException {
		
		BufferedReader br = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\output0"+epsilon+""));		
		BufferedReader br2 = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\output0"+epsilon+"_"));		
		BufferedWriter bw = new BufferedWriter(new FileWriter(svm_dataset+"fold-"+fold+"\\finalresult0"+epsilon+""));
		
//		BufferedReader br = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\outtrain0"+epsilon+""));		
//		BufferedReader br2 = new BufferedReader(new FileReader(svm_dataset+"fold-"+fold+"\\outtrain0"+epsilon+"_"));		
//		BufferedWriter bw = new BufferedWriter(new FileWriter(svm_dataset+"fold-"+fold+"\\finalresult0"+epsilon+""));
		
		int total = 0;
		String line;
		
		while ((line = br.readLine()) != null){
			String[] f = line.split(" ");
			Double cls = Double.parseDouble(f[0]);
			
			if(cls > 0) {
				bw.write("1"+"\n");
				total++;
			}
			else {
				String line_nonpos = br2.readLine();
				String[] f_nonpos = line_nonpos.split(" ");
				Double cls_nonpos = Double.parseDouble(f_nonpos[0]);
				
				if(cls_nonpos < 0){
					bw.write("0"+"\n");
					total++;
				}
				else {
					bw.write("-1"+"\n");
					total++;
				}
			}
		}		
		
		br.close();		
		br2.close();
		bw.close();
		
		System.out.println("Total "+total);
	}

}
